const static double PI = 3.14;
class Shape {
    public:
        virtual double area() = 0;
};

class Square : public Shape {
    protected:
        double w;
    public:
        Square(double a) {
            w = a;
        }

        double area() {
            return w * w;
        }
};

class Circle : public Square {
    public:
        Circle(double r):Square(r) {}
        double area() {
            return w * w * PI; 
        }
};

class Triangle : public Square {
    protected:
        double h;
    public:
        Triangle(double w,double h):Square(w),h(h) {

        }

        double area () {
            return 0.5 * w * h;
        }
};

class Rectangle : public Triangle {
    public:
        Rectangle(double w,double h):Triangle(w,h) {}
        double area() {
            return w * h;
        }
};

double sum(Shape *s[],int n) {
    double sum = 0.0;
    for (int i = 0 ;i < n;i++) {
        sum += s[i]->area();
    }
    return sum;
}

#include<iostream>
using namespace std;

int main() {
    Shape *s[4];
    s[0] = new Square(4);
    s[1] = new Triangle(3,6);
    s[2] = new Rectangle(3,6);
    s[3] = new Circle(10);
    int size = sizeof(s) / sizeof(s[0]);
    cout << "size = " << size << endl;
    cout << "begin s = " << begin(s) << endl;
    int length = end(s) - begin(s);
    cout << "s length = " << length << endl;
    double total = sum(s,size);
    cout << "The total area is : " << total << endl;
    return 0;
}
